package com.buric.web.admin.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.buric.api.dto.admin.LoginAdmin;
import com.buric.common.exception.ServiceException;
import com.buric.web.admin.model.domain.User;
import com.buric.web.admin.mapper.AdminMapper;
import com.buric.web.admin.service.AdminService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 管理员ServiceImpl
 * </p>
 *
 * @author zhou.wei
 * @version 1.0
 * @since 2025/2/12 14:29
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, User> implements AdminService {
    @Override
    public LoginAdmin getUserByUsername(String username) {
        User user = this.getOne(Wrappers.<User>lambdaQuery().eq(User::getUsername, username));
        if(user == null){
             throw new ServiceException("未找到管理员信息");
        }
        LoginAdmin loginUser = new LoginAdmin();
        loginUser.setId(user.getId());
        loginUser.setUsername(user.getUsername());
        loginUser.setNickName(user.getNickName());
        loginUser.setSex(user.getGender());
        return loginUser;
    }
}
